package _designPatterm.单例模式.饿汉式;

/**
 * 饿汉式:静态常量
 * 可用,但会造成内存浪费
 */
public class singletonTest01 {
    public static void main(String[] args) {
        Singleton instance = Singleton.getInstance();
        Singleton instance1 = Singleton.getInstance();
        System.out.println(instance == instance1);
    }
}

class Singleton {
    private Singleton() {
    }

    private static final Singleton instance = new Singleton();

    static Singleton getInstance() {
        return instance;
    }

}
